<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
  <title>权限细节编辑</title>
</head>
<body>
<script type="text/javascript">
    Ext.onReady(function () {
        var pdId = Ext.create('Ext.form.field.Hidden', {
            name:'id',
            value:'<%=params[:id]%>'
        });

        var name = Ext.create('Ext.form.field.Text', {
            fieldLabel:'权限名称',
            name:'name',
            anchor:'90%'
        });

        var sysController = Ext.create('Ext.form.ComboBox', {
            store:sysControllerStore,
            fieldLabel:'控制器',
            allowBlank:false,
            blankText:"控制器必须选择",
            valueField:'id',
            displayField:'name',
            name:'sys_controller_id', //如果不想提交displayField，则在这儿指定要提交的Key，value就是valueField．
            emptyText:'请选择...',
            loadingText:'搜索中...',
            anchor:'95%',
            //pageSize: 10,
            minChars:0
        });

        sysController.on('select', function () {
            sysActionStore.removeAll();
            sysActionStore.getProxy().extraParams = {'sys_controller_id':sysController.getValue()};
            sysActionStore.load();
        });

        var sysAction = Ext.create('Ext.form.ComboBox', {
            store:sysActionStore,
            fieldLabel:'行为方法',
            allowBlank:false,
            blankText:"行为方法必须选择",
            valueField:'id',
            displayField:'name',
            name:'sys_action_id', //如果不想提交displayField，则在这儿指定要提交的Key，value就是valueField．
            emptyText:'请选择...',
            loadingText:'搜索中...',
            anchor:'95%',
            //pageSize: 10,
            minChars:0
        });

        var couplingInterface = Ext.create('Ext.form.RadioGroup', {
            //width : 220,
            fieldLabel:'介面相关',
            //hideLabel:true,
            //style:'margin-left:100px;margin-top:20px',
            //name:'financial_management',
            columns:2,
            anchor:'100%',
            vertical:false,
            items:[
                {boxLabel:'是', inputValue:'1', name:'coupling_interface'},
                {boxLabel:'否', inputValue:'0', name:'coupling_interface'}
            ]
        });

        var subType = Ext.create('Ext.form.field.Text', {
            fieldLabel:'类型',
            name:'sub_type',
            anchor:'90%'
        });

        var params = Ext.create('Ext.form.field.Text', {
            fieldLabel:'参数',
            name:'params',
            anchor:'90%'
        });

        var desc = Ext.create('Ext.form.TextArea', {
            fieldLabel:'备注',
            name:'description',
            allowBlank:true,
            height:80,
            anchor:'90%'
        });

        //提交按钮
        var submitButton = Ext.create('Ext.Button', {
            text:'提交',
            iconCls:'icon-save',
            handler:function () {
                submitButton.setDisabled(true);
                if (editPrivilegeFormPanel.form.isValid()) {
                    editPrivilegeFormPanel.form.submit({
                        success:function (result, resp) {
                            if (resp.result.info.indexOf("成功") >= 0) {
                                editPrivilegeDetailWin.destroy();
                            } else {
                                Ext.MessageBox.show({
                                    title:'消息',
                                    msg:resp.result.info,
                                    buttons:Ext.MessageBox.OK,
                                    icon:Ext.MessageBox.WARNING
                                });
                            }
                            submitButton.enable();
                        },
                        failure:function (result, request) {
                            submitButton.enable();
                            Ext.MessageBox.show({
                                title:'消息',
                                msg:"通讯失败，请从新操作",
                                buttons:Ext.MessageBox.OK,
                                icon:Ext.MessageBox.WARNING
                            });
                        }
                    });
                }
                else {
                    submitButton.enable();

                }
            }
        })

        var editPrivilegeFormPanel = Ext.create('Ext.form.Panel', {
            fieldDefaults:{
                labelWidth:75,
                labelAlign:'right'
            },
            width:'345',
            frame:true,
            url:'/privilege/updateSysPrivilegeDetail',
            method:'GET',
            reader:Ext.create('Ext.data.reader.Json', {
                model:'SysPrivilegeDetail',
                root:'root'
            }),
            items:[pdId, name, sysController, sysAction, couplingInterface,subType, params, desc],
            buttons:[submitButton, {
                text:'关闭',
                handler:function () {
                    editPrivilegeDetailWin.destroy();
                }
            }]
        });

        sysControllerStore.load({callback:function (record, options, success) {
            if (success) {
                sysActionStore.getProxy().extraParams = {'sys_controller_id':<%=@privilegeDetail.sys_controller_id%>};
                sysActionStore.load({callback:function (record, options, success) {
                    if (success) {
                        editPrivilegeFormPanel.form.load({
                            url:'/privilege/getPrivilegeDetailById?id=' + pdId.getValue(),
                            method:'GET',
                            waitMsg:'正在载入数据...',
                            success:function (form, action) {
                            },
                            failure:function (form, action) {
                                Ext.MessageBox.alert('提示信息', '信息加载失败');
                            }
                        });
                    } else {
                        Ext.MessageBox.alert('操作', '失败！');
                    }
                }});
            } else {
                Ext.MessageBox.alert('操作', '失败！');
            }
        }});

        editPrivilegeFormPanel.render('sys_privilege_form');
    })
</script>
<div id="sys_privilege_form"></div>
</body>
</html>
